package com.wang;

import lombok.Value;
import org.w3c.dom.Text;

import java.security.Key;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * @ProjectName: untitled
 * @Titile: MapDemo
 * @Author: 王亦凡1
 * @Description: TODO
 */
public class MapDemo {
    public static void main(String[] args) {
        test0();
        test1();
        test2();

    }
    public static void test3(){
        Map<String,Double>map=new HashMap<>();
        map.put("zhangsan",200.0);
        map.put("zhaoliu",300.0);
        map.put("wangbiao",200.0);
        map.put("liunanshan",200.0);
        map.forEach((key, value) -> System.out.println(key + "---" + value));
    }

    public static void test2(){
        Map<String,Double>map=new HashMap<>();
        map.put("zhangsan",200.0);
        map.put("zhaoliu",300.0);
        map.put("wangbiao",200.0);
        map.put("liunanshan",200.0);
        //1.将map集合转成set集合（将map集合中的key-value绑定成一个对象entry
        Set<Map.Entry<String,Double>>entrySet=map.entrySet();
        //2.遍历set集合
        for(Map.Entry<String,Double>entry:entrySet){
            String Key=entry.getKey();
            Double value=entry.getValue();
            System.out.println(Key+"----"+value);
        }
    }

    public static void test1(){
        Map<String,Double>map=new HashMap<>();
        map.put("zhangsan",200.0);
        map.put("zhaoliu",300.0);
        map.put("wangbiao",200.0);
        map.put("liunanshan",200.0);
        //将map中所有的值放在set中
        Set<String>Keyset= map.keySet();
        //遍历key集合
        for(String key:Keyset){
            Double value=map.get(key);
            System.out.println(key+"---"+value);
        }

    }

    public  static void test0 (){
        Map<String, Double>map = new HashMap<>();
        map.put("zhangsan",200.0);
        map.put("zhaoliu",300.0);
        map.put("wangbiao",200.0);
        map.put("liunanshan",200.0);
        System.out.println(map);
        map.remove("zhangsan");
        System.out.println(map);
//        map.clear();
//        System.out.println(map);
        boolean b=map.containsKey("wangbiao");
        System.out.println(b);


        boolean b2=map.containsValue(200.0);
        System.out.println(b2);


        boolean empty=map.isEmpty();
        System.out.println("empty");


        int size=map.size();
        System.out.println(size);
    }
}
